package com.chlitina.store.modules.cash.model.recharge;

import com.chlitina.store.modules.cash.model.AllCardPayment;
import com.chlitina.store.modules.cash.model.AllCardPaymentDetail;
import com.chlitina.store.modules.cash.model.Member;
import com.chlitina.store.modules.cash.service.PaymentUility;
import com.chlitina.store.modules.employee.entity.Employee;

public class Recharge {
	private RechargeItemPayment payment = new RechargeItemPayment();
	private Employee employee;
	private float money;

	public float getMoney() {
		return money;
	}

	public void setMoney(float money) {
		this.money = money;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public RechargeItemPayment getPayment() {
		return payment;
	}

	public void setPayment(RechargeItemPayment payment) {
		this.payment = payment;
	}

	public void updatePayment(Member member) {
		payment.reset();
		AllCardPayment allcard = PaymentUility.findBestAllCardPayment(
				member.getAvaibleAllCards(), this);
		if (allcard == null) {
			payment.setCash(getMoney());
		} else {
			AllCardPaymentDetail detail = new AllCardPaymentDetail();
			detail.setCardPayment(allcard);
			detail.setCurrentLeftMoney(allcard.getCurrentMoney());
			detail.appendPay(getMoney());
			payment.setCardAll(detail);
			member.updateAvailableAllCards();
		}
	}
}
